package com.nuanshui.heatedloan.web.appsystem;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.nuanshui.framework.res.ResourceFacade;
import com.nuanshui.framework.res.qiniu.UpLoadFileResult;
import com.nuanshui.framework.res.qiniu.UpLoadFileVO;
import com.nuanshui.heatedloan.baseservice.facade.ImageService;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.model.Image;
import com.nuanshui.heatedloan.pageable.Pager;
import com.nuanshui.heatedloan.web.ApiController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController()
@RequestMapping("/cms/manage/imagemanage")
public class ImageManageController extends ApiController{
	
	
	@Autowired
	private ResourceFacade resourceFacade;

	@Reference(url = GlobalParam.BASESERVICE_DUBBO_SERVER, timeout = GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.BASESERVICE_DUBBO_SERVER_VERSION)
	private ImageService imageService;
	
	@RequestMapping("/list")
	public String list(Pager<Image> pager){
		pager=imageService.list(pager);
		return success(pager.asHashMap());
	}
	
	@RequestMapping("/saveImage")
	public String saveImage(String imageStr){
		UpLoadFileVO item = JSON.parseObject(imageStr, UpLoadFileVO.class);
		Image image = UpLoadFileResult.convertUpLoadFileToImage(item);
		String imageId=imageService.insert(image);
		image.setId(imageId);
		return success(image);
	}

	@RequestMapping(value="/delete")
	public String delete(String id){
		imageService.delete(id);
		return success();
	}

}
